<template>
  <el-form ref="form" :model="user" label-width="80px">


    <el-form-item label="默认首页" prop="defaultIndex">
      <el-select v-model="user.defaultIndex"
                 placeholder="默认首页"
                 >
        <el-option
          v-for="(item, index) in this.indexList"
          :key="index"
          :label="item.label"
          :value="item.value"/>
      </el-select>
    </el-form-item>


    <el-form-item>
      <el-button type="primary" size="mini" @click="submit">保存</el-button>
      <el-button type="danger" size="mini" @click="close">关闭</el-button>
    </el-form-item>
  </el-form>
</template>

<script>

import { updateDefaultIndex } from "@/api/system/user"
import { listTIndex } from "@/api/business/showIndex"

export default {
  name: "defaultIndex",
  props: {
    user: {
      type: Object
    }
  },
  data() {
    return {
      // user: {
      //   defaultIndex: ''
      // },
      indexList: []
    }
  },
  created() {
    this.getIndexList()
  },
  methods: {
    submit() {

      console.log(this.user.defaultIndex)

      updateDefaultIndex(this.user.defaultIndex).then(response => {
        this.$modal.msgSuccess("修改成功")
      })

    },
    close() {
      this.$tab.closePage()
    },
    getIndexList() {

      listTIndex(null).then(response => {
        // console.log(response)

        for (let item of response.rows) {
          let temp = {}
          temp['value'] = item.indexUrl
          temp['label'] = item.indexName

          this.indexList.push(temp)
        }

      })
    },
  }
}
</script>

<style scoped>

</style>
